// FrontEnd Plus GUI for JAD
// DeCompiled : HibernatePlugin.class

package middlegen.plugins.hibernate;

import java.util.ArrayList;

import middlegen.FileProducer;
import middlegen.MiddlegenException;
import middlegen.javax.JavaPlugin;
import middlegen.plugins.hibernate.interfaces.JavaTypeMapper;
import middlegen.plugins.hibernate.swing.JHibernateColumnSettingsPanel;
import middlegen.plugins.hibernate.swing.JHibernateTableSettingsPanel;
import middlegen.swing.JColumnSettingsPanel;
import middlegen.swing.JTableSettingsPanel;
import middlegen.util.BooleanNode;

public class HibernatePlugin extends JavaPlugin
{

	private String moduleName;
	private boolean _genXdocletTags;
	private boolean _genLazyNotProxy;
	private boolean _genIntergratedCompositeKeys;
	private String _standardIdGenerator;
	private String _standardCascade;
	private String _beansuffix;
	private String _databaseSchema;
	private String _persister;
	private String _batchsize;
	private String _classDescription;
	private String _fieldDescription;
	private String _classScope;
	private String _fieldScope;
	private String _getScope;
	private String _setScope;
	private String _accessField;
	private String _extends;
	private String _beanPropertyType;
	private JavaTypeMapper _javaTypeMapper;
	private boolean _proxy;
	private final BooleanNode _proxyNode = BooleanNode.createRoot(false);
	private boolean _plainCKeys;
	private boolean _versionUnsavedValue;
	private boolean _versionUnsavedValueCKeys;
	private final BooleanNode _plainCKeyNode = BooleanNode.createRoot(false);
	private boolean _lifecycle;
	private final BooleanNode _lifecycleNode = BooleanNode.createRoot(false);
	private boolean _validatable;
	private final BooleanNode _validatableNode = BooleanNode.createRoot(false);
	private boolean _equalsHashcode;
	private final BooleanNode _equalsHashcodeNode = BooleanNode.createRoot(false);
	private boolean _mutable;
	private final BooleanNode _mutableNode = BooleanNode.createRoot(false);
	private boolean _dynamicUpdate;
	private final BooleanNode _dynamicUpdateNode = BooleanNode.createRoot(false);
	private boolean _dynamicInsert;
	private final BooleanNode _dynamicInsertNode = BooleanNode.createRoot(false);
	private boolean _selectBeforeUpdate;
	private final BooleanNode _selectBeforeUpdateNode = BooleanNode.createRoot(false);
	private ArrayList _implements;
	private boolean _columnsUpdateable;
	private boolean _columnsInsertable;
	private boolean _columnsIncToString;
	private boolean _columnsGenProperty;
	private boolean _columnsIncEquals;
	public static final String StandardIdGenerator = "";
	public static final String StandardCascadeId = "none";
	public static final String FieldId = "field";
	public static final String PropertyId = "property";
	public static final String PublicId = "public";
	public static final String PrivateId = "private";
	public static final String ProtectedId = "protected";
	public static final String ColPropertyId = "property";
	public static final String ColKeyId = "key";
	public static final String ColForeignKeyId = "foreign key";
	public static final String ColCompoundKeyId = "compound key";
	public static final String ColVersionId = "version";
	public static final String ColTimestampId = "timestamp";

	public HibernatePlugin()
	{
		moduleName = "xmx0632";
		_genXdocletTags = false;
		_genLazyNotProxy = false;
		_genIntergratedCompositeKeys = false;
		_standardIdGenerator = "";
		_standardCascade = "none";
		_beansuffix = "";
		_databaseSchema = "";
		_persister = "";
		_batchsize = "";
		_classDescription = "";
		_fieldDescription = "";
		_classScope = "public";
		_fieldScope = "private";
		_getScope = "public";
		_setScope = "public";
		_accessField = "property";
		_extends = "";
		_beanPropertyType = "unbound";
		_proxy = false;
		_plainCKeys = true;
		_versionUnsavedValue = false;
		_versionUnsavedValueCKeys = true;
		_lifecycle = false;
		_validatable = false;
		_equalsHashcode = false;
		_mutable = true;
		_dynamicUpdate = true;
		_dynamicInsert = false;
		_selectBeforeUpdate = false;
		_implements = new ArrayList();
		_columnsUpdateable = true;
		_columnsInsertable = true;
		_columnsIncToString = false;
		_columnsGenProperty = true;
		_columnsIncEquals = false;
		setDisplayName("Hibernate");
//		_implements.add("cn.com.asb.mdms.base.bo.BaseObject");
	}

	public void setStandardCascade(String s)
	{
		_standardCascade = s;
	}

	public void setStandardGeneratorScheme(String s)
	{
		if("native".equals(s))
			_standardIdGenerator = s;
		else
			_standardIdGenerator = "";
	}

	public void setBeansuffix(String s)
	{
		_beansuffix = s;
	}

	public void setLifecycle(boolean flag)
	{
		_lifecycle = flag;
	}

	public void setEqualsHashcode(boolean flag)
	{
		_equalsHashcode = flag;
	}

	public void setValidatable(boolean flag)
	{
		_validatable = flag;
	}

	public void setProxy(boolean flag)
	{
		_proxy = flag;
	}

	public void setPlainCompoundKeys(boolean flag)
	{
		_plainCKeys = flag;
	}

	public void setVersionUnsavedValueSimpleKey(boolean flag)
	{
		_versionUnsavedValue = flag;
	}

	public void setVersionUnsavedValueCompoundKeys(boolean flag)
	{
		_versionUnsavedValueCKeys = flag;
	}

	public void setDynamicUpdate(boolean flag)
	{
		_dynamicUpdate = flag;
	}

	public void setDynamicInsert(boolean flag)
	{
		_dynamicInsert = flag;
	}

	public void setSelectBeforeUpdate(boolean flag)
	{
		_selectBeforeUpdate = flag;
	}

	public void setMutable(boolean flag)
	{
		_mutable = flag;
	}

	public void setDatabaseSchema(String sname)
	{
		_databaseSchema = sname.trim();
	}

	public void setClassDescription(String classd)
	{
		_classDescription = classd.trim();
	}

	public void setFieldDescription(String fieldd)
	{
		_fieldDescription = fieldd.trim();
	}

	public void setAccessField(String val)
	{
		_accessField = val.trim();
	}

	public void setClassScope(String classscope)
	{
		_classScope = classscope.trim();
	}

	public void setFieldScope(String fieldscope)
	{
		_fieldScope = fieldscope.trim();
	}

	public void setFieldGetScope(String getscope)
	{
		_getScope = getscope.trim();
	}

	public void setFieldSetScope(String setscope)
	{
		_setScope = setscope.trim();
	}

	public void setBeanPropertyType(String value)
	{
		_beanPropertyType = value.trim();
	}

	public void setExtends(String basec)
	{
		_extends = basec.trim();
	}

	public void setImplements(ArrayList impls)
	{
		_implements = impls;
	}

	public void setPersister(String dPersister)
	{
		_persister = dPersister.trim();
	}

	public void setBatchSize(String dBatchSize)
	{
		_batchsize = dBatchSize.trim();
	}

	public void setColumnsUpdateable(boolean flag)
	{
		_columnsUpdateable = flag;
	}

	public void setColumnsInsertable(boolean flag)
	{
		_columnsInsertable = flag;
	}

	public void setColumnsIncToString(boolean flag)
	{
		_columnsIncToString = flag;
	}

	public void setColumnsIncEquals(boolean flag)
	{
		_columnsIncEquals = flag;
	}

	public void setColumnsGenProperty(boolean flag)
	{
		_columnsGenProperty = flag;
	}

	public void setGenXDocletTags(boolean flag)
	{
		_genXdocletTags = flag;
	}

	public void setGenLazyNotProxy(boolean flag)
	{
		_genLazyNotProxy = flag;
	}

	public void setGenIntergratedCompositeKeys(boolean flag)
	{
		_genIntergratedCompositeKeys = flag;
	}

	public void setJavaTypeMapper(String javaTypeMapper)
		throws ClassNotFoundException, IllegalAccessException, InstantiationException
	{
		if(javaTypeMapper != null)
			_javaTypeMapper = (JavaTypeMapper)getClass().getClassLoader().loadClass(javaTypeMapper).newInstance();
	}

	public JavaTypeMapper getJavaTypeMapper()
	{
		return _javaTypeMapper;
	}

	public boolean getGenIntergratedCompositeKeys()
	{
		return _genIntergratedCompositeKeys;
	}

	public boolean getGenXDocletTags()
	{
		return _genXdocletTags;
	}

	public boolean getGenLazyNotProxy()
	{
		return _genLazyNotProxy;
	}

	public Class getTableDecoratorClass()
	{
		return middlegen.plugins.hibernate.HibernateTable.class;
	}

	public Class getColumnDecoratorClass()
	{
		return middlegen.plugins.hibernate.HibernateColumn.class;
	}

	public String getStandardCascade()
	{
		return _standardCascade;
	}

	public String getStandardGeneratorScheme()
	{
		return _standardIdGenerator;
	}

	public String getBeansuffix()
	{
		return _beansuffix;
	}

	public boolean isLifecycle()
	{
		return _lifecycle;
	}

	public boolean isEqualsHashcode()
	{
		return _equalsHashcode;
	}

	public boolean isValidatable()
	{
		return _validatable;
	}

	public boolean isProxy()
	{
		return _proxy;
	}

	public boolean isPlainCompoundKeys()
	{
		return _plainCKeys;
	}

	public boolean isVersionUnsavedValueSimpleKey()
	{
		return _versionUnsavedValue;
	}

	public boolean isVersionUnsavedValueCompoundKeys()
	{
		return _versionUnsavedValueCKeys;
	}

	public boolean isDynamicInsert()
	{
		return _dynamicInsert;
	}

	public boolean isSelectBeforeUpdate()
	{
		return _selectBeforeUpdate;
	}

	public boolean isDynamicUpdate()
	{
		return _dynamicUpdate;
	}

	public boolean isMutable()
	{
		return _mutable;
	}

	public boolean isColumnsUpdateable()
	{
		return _columnsUpdateable;
	}

	public boolean isColumnsInsertable()
	{
		return _columnsInsertable;
	}

	public boolean isColumnsIncludeToString()
	{
		return _columnsIncToString;
	}

	public boolean isColumnsIncludeEquals()
	{
		return _columnsIncEquals;
	}

	public boolean isColumnsGenProperty()
	{
		return _columnsGenProperty;
	}

	public JColumnSettingsPanel getColumnSettingsPanel()
	{
		return new JHibernateColumnSettingsPanel();
	}

	public JTableSettingsPanel getTableSettingsPanel()
	{
		return new JHibernateTableSettingsPanel();
	}

	public boolean getColumnsUpdateable()
	{
		return _columnsUpdateable;
	}

	public boolean getColumnsInsertable()
	{
		return _columnsInsertable;
	}

	public boolean getColumnsIncludeToString()
	{
		return _columnsIncToString;
	}

	public boolean getColumnsIncludeEquals()
	{
		return _columnsIncEquals;
	}

	public boolean getColumnsGenProperty()
	{
		return _columnsGenProperty;
	}

	public String getAccessField()
	{
		return _accessField;
	}

	public String getFieldScope()
	{
		return _fieldScope;
	}

	public String getFieldGetScope()
	{
		return _getScope;
	}

	public String getFieldSetScope()
	{
		return _setScope;
	}

	public String getBeanPropertyType()
	{
		return _beanPropertyType.trim();
	}

	public void validate()
		throws MiddlegenException
	{
		super.validate();
	}

	protected String getDatabaseSchema()
	{
		return _databaseSchema;
	}

	protected String getPersister()
	{
		return _persister;
	}

	protected String getBatchSize()
	{
		return _batchsize;
	}

	protected String getClassDescription()
	{
		return _classDescription;
	}

	protected String getFieldDescription()
	{
		return _fieldDescription;
	}

	protected String getClassScope()
	{
		return _classScope;
	}

	protected String getExtends()
	{
		return _extends;
	}

	protected boolean getLifecycle()
	{
		return _lifecycle;
	}

	protected boolean getEqualsHashcode()
	{
		return _equalsHashcode;
	}

	protected BooleanNode getLifecycleNode()
	{
		return _lifecycleNode;
	}

	protected BooleanNode getEqualsHashcodeNode()
	{
		return _equalsHashcodeNode;
	}

	protected boolean getValidatable()
	{
		return _validatable;
	}

	protected BooleanNode getValidatableNode()
	{
		return _validatableNode;
	}

	protected boolean getPlainCompoundKeys()
	{
		return _plainCKeys;
	}

	protected BooleanNode getPlainCompoundKeyNode()
	{
		return _plainCKeyNode;
	}

	protected boolean getProxy()
	{
		return _proxy;
	}

	protected BooleanNode getProxyNode()
	{
		return _proxyNode;
	}

	protected boolean getDynamicUpdate()
	{
		return _dynamicUpdate;
	}

	protected boolean getDynamicInsert()
	{
		return _dynamicInsert;
	}

	protected boolean getSelectBeforeUpdate()
	{
		return _selectBeforeUpdate;
	}

	protected BooleanNode getDynamicUpdateNode()
	{
		return _dynamicUpdateNode;
	}

	protected BooleanNode getDynamicInsertNode()
	{
		return _dynamicInsertNode;
	}

	protected BooleanNode getSelectBeforeUpdateNode()
	{
		return _selectBeforeUpdateNode;
	}

	protected boolean getMutable()
	{
		return _mutable;
	}

	protected BooleanNode getMutableNode()
	{
		return _mutableNode;
	}

	protected ArrayList getImplements()
	{
		return (ArrayList)_implements.clone();
	}

	protected void registerFileProducers()
	{
		/**
		 * for hibernate
		 */
		System.out.println("template file path:".concat(getDestinationDir().getName()));
		addConfiguredFileproducer(new FileProducer(getDestinationDir(), (new StringBuffer("{0}")).append(getBeansuffix())
				.append(".hbm.xml").toString(), getClass().getResource("hibernate-hbm.xml")));
		addConfiguredFileproducer(new FileProducer(getDestinationDir(),  (new StringBuffer("{0}")).append(getBeansuffix())
				.append("Dao.java").toString(), getClass().getResource("hibernate-DAO.java")));
		addConfiguredFileproducer(new FileProducer(getDestinationDir(),  (new StringBuffer("{0}")).append(getBeansuffix())
				.append("DaoImpl.java").toString(), getClass().getResource("hibernate-DAOImpl.java")));
		addConfiguredFileproducer(new FileProducer(getDestinationDir(),  (new StringBuffer("{0}")).append(getBeansuffix())
				.append("Manager.java").toString(), getClass().getResource("hibernate-service.java")));
		addConfiguredFileproducer(new FileProducer(getDestinationDir(),  (new StringBuffer("{0}")).append(getBeansuffix())
				.append("ManagerImpl.java").toString(), getClass().getResource("hibernate-serviceImpl.java")));
		addConfiguredFileproducer(new FileProducer(getDestinationDir(),  (new StringBuffer("applicationContext-{0}")).append(getBeansuffix())
				.append("-conf.xml").toString(), getClass().getResource("hibernate-conf.xml")));
        addConfiguredFileproducer(new FileProducer(getDestinationDir(),  (new StringBuffer("{0}")).append(getBeansuffix())
                .append("ManagerTest.java").toString(), getClass().getResource("hibernate-testservice.java")));
        
        /**
         * for struts
         */
        addConfiguredFileproducer(new FileProducer(getDestinationDir(),  (new StringBuffer("{0}")).append(getBeansuffix())
				.append("Action.java").toString(), getClass().getResource("struts-action.java")));
        addConfiguredFileproducer(new FileProducer(getDestinationDir(),  (new StringBuffer("{0}")).append(getBeansuffix())
				.append("-struts-config.xml").toString(), getClass().getResource("struts-config.xml")));
        addConfiguredFileproducer(new FileProducer(getDestinationDir(),  (new StringBuffer("{0}")).append(getBeansuffix())
				.append("List.jsp").toString(), getClass().getResource("struts-list.jsp")));
        addConfiguredFileproducer(new FileProducer(getDestinationDir(),  (new StringBuffer("{0}")).append(getBeansuffix())
				.append("Edit.jsp").toString(), getClass().getResource("struts-edit.jsp")));
	}

	public String getModuleName() {
		return moduleName;
	}

	public void setModuleName(String moduleName) {
		this.moduleName = moduleName;
	}

}
